package agent

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/agentClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type EditRebatesLevelLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewEditRebatesLevelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditRebatesLevelLogic {
	return &EditRebatesLevelLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *EditRebatesLevelLogic) EditRebatesLevel(req *types.EditRebatesLevelReq) (resp *types.IsSuccessInfo, err error) {
	// 返佣等级管理--修改
	_detail := make([]*rpc.RebatesCondition, len(req.Detail))
	for _, v := range req.Detail {
		_detail = append(_detail, &rpc.RebatesCondition{
			ConditionType:  v.ConditionType,
			ConditionValue: v.ConditionValue,
		})
	}
	report, err := l.svcCtx.AgentRPC.EditRebatesLevel(context.Background(), &rpc.EditRebatesLevelReq{
		Level:  req.Level,
		Detail: _detail,
		Remark: req.Remark,
	})
	if err != nil {
		logx.Error(l.ctx, err)
		return nil, err
	}

	resp = &types.IsSuccessInfo{
		IsSuccess: report.IsSuccess,
	}

	return
}
